package cn.springboottest.util;

import cn.springboottest.domain.Stu;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;



public class LoadStu {
    Connection con;
    List<Stu> printStu() throws SQLException {//仅仅打印信息
        List<Stu> res=new ArrayList<>();//学生信息集
        Stu stu=new Stu();//初始化一个学生对象，用于每次存储学生信息，并存入res集中
        //String sql = "SELECT id,username,pass,java,math,os FROM stu";
        String sql = "SELECT*FROM stu";
        //创建Statement对象
        Statement stmt=con.createStatement();
        //建立结果集
        ResultSet rs=stmt.executeQuery(sql);
        while (rs.next()){
            stu.setId(rs.getLong(1));
            stu.setUsername(rs.getString(2));
            stu.setPass(rs.getString(3));
            stu.setJava(rs.getDouble(4));
            stu.setMath(rs.getDouble(5));
            stu.setOs(rs.getDouble(6));
            res.add(stu);
        }
        //关闭结果集
        rs.close();
        //关闭Statement对象
        stmt.close();
        return res;
    }
}
